<?php 
include("lib/core/User.php");

define('FILE_PATH', __DIR__);
define('COMMON_PATH', FILE_PATH."/lib/common");

include(COMMON_PATH."/config.php");
include(COMMON_PATH."/function.php");
include(COMMON_PATH."/DB.php");

error_reporting(0);

// print_r($_POST);

$user =  new User();

$op = empty($_POST["action"])?$_GET["action"]:$_POST["action"];

switch ($op) {
	case 'region':
		$region_id=empty($_POST["region_id"])?$_GET["region_id"]:$_POST["region_id"];
		$region_type=empty($_POST["region_type"])?$_GET["region_type"]:$_POST["region_type"];
		$user->getRegion($region_id,$region_type);
		break;
	case 'clients':
		$token=empty($_POST["token"])?$_GET["token"]:$_POST["token"];
		$user->getClientList($token);
		break;
	case 'online':
		$token = $_POST["token"];
		$user->isOnline($token);
		break;
	case 'login':
		$userid = empty($_POST["user"])?$_GET["user"]:$_POST["user"];
		$upw = empty($_POST["upw"])?$_GET["upw"]:$_POST["upw"];
		$user->login( $userid,$upw );
		break;
	case 'loginPhone':
		$userid = empty($_POST["user"])?$_GET["user"]:$_POST["user"];
		$upw = empty($_POST["upw"])?$_GET["upw"]:$_POST["upw"];
		$user->loginPhone( $userid,$upw );
		break;
	case 'register':
		$uname=empty($_POST["uname"])?$_GET["uname"]:$_POST["uname"];
		$pwd=empty($_POST["upw"])?$_GET["upw"]:$_POST["upw"];
		$email=empty($_POST["email"])?$_GET["email"]:$_POST["email"];
		$register_ip=empty($_POST['register_ip']) ? $_SERVER['REMOTE_ADDR']:$_POST['register_ip'];
		$OutletId=empty($_POST["OutletId"])?$_GET["OutletId"]:$_POST["OutletId"];
		$user->register($uname,$pwd,$email,$register_ip,$OutletId);
		break;
	case 'active':
		$token = $_GET['token'];
		$user->active( $token );
		break;
	case 'modify':
		$token = $_POST["token"];
		$data = $_POST;
		unset($data["type"]);
		unset($data["action"]);
		unset($data["token"]);
		$user->modify($token,$data);
		break;
	case 'logout':
		$token = $_POST["token"];
		$user->logout($token);
		break;
	case 'userinfo':
		$token=empty($_POST["token"])?$_GET["token"]:$_POST["token"];
		$user -> getUserInfo($token);
		break;
	case 'userinfoByuid':
		$token=empty($_POST["uid"])?$_GET["uid"]:$_POST["uid"];
		$user -> getUserInfoByuid($token);
		break;
	case 'menu':
		$token=$_POST['token'];
		// $token='8ecd60a9-41ea-287b-db80-9d5d447afc60';
		$user -> getMenu($token);
		break;
	case 'checkname':
		$name=empty($_POST['ClientName'])?$_GET['ClientName']:$_POST['ClientName'];
		$user->checkname($name);
		break;
	case 'checkLineByName':
		$name=empty($_POST['LineName'])?$_GET['LineName']:$_POST['LineName'];
		$user->checkLineByName($name);	
		break;
	default:
		$user->showError();
		break;
}

?>